package com.vip.zuul.service.impl;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.vip.zuul.service.IRequestCheckService;

/**
 * Description : 
 * @Author Evan Liu
 * @Date 2018年11月13日
 */
public class RequestCheckServiceImpl implements IRequestCheckService{
	@Override
	public boolean checkRequestAuthority(HttpServletRequest request) {
		//http://localhost:8080/CarsiLogCenter_new/idpstat.jsp?action=idp.sptopn
		//request.getRequestURL() :		http://localhost:8080/CarsiLogCenter_new/idpstat.jsp
		//request.getRequestURI() :		/CarsiLogCenter_new/idpstat.jsp
		//request.getContextPath():		/CarsiLogCenter_new
		//request.getServletPath():	 	/idpstat.jsp
		//request.getQueryString():		action=idp.sptopn
		String uri = request.getRequestURI();
		String method = request.getMethod();
		Map<String, String[]> parameters = request.getParameterMap();
		Map<String, String> headers = getHeadersInfo(request);
		checkURLToken(request);
		return false;
	}
	
	public static boolean checkURLToken(HttpServletRequest request) {
		return true;
	}
	
	private Map<String, String> getHeadersInfo(HttpServletRequest request) {
		Map<String, String> map = new HashMap<String, String>();
		Enumeration<String> headerNames = request.getHeaderNames();
		while (headerNames.hasMoreElements()) {
			String key = (String) headerNames.nextElement();
			String value = request.getHeader(key);
			map.put(key, value);
		}
		return map;
	}

	@Override
	public boolean checkRequestFrequence(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return false;
	}
}


